package com.qf.mapper;

import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author dell
 * @version V1.0
 * @Date 2022/4/22 19:13:15
 */
@SuppressWarnings("rawtypes")
public interface statMapper {

    /**
     * 销售类别统计
     * @return
     */
    @Select(" select pc.name as `name`,sum(og.price) as `value` " +
            " from dts_order_goods og" +
            " join dts_order o on o.id = og.order_id" +
            " join dts_goods g on g.id = og.goods_id" +
            " join dts_category c on g.category_id = c.id" +
            " join dts_category pc on pc.id = c.pid" +
            " where og.deleted=0 and o.order_status not in(101,102,103) " +
            " group by pc.name ")
    List<CategorySellAmts> categorySellStatis();


    @Select(" select date_format(t.add_time,\"%Y-%m-%d\") as dayStr,count(1) as cnts  " +
            " from dts_user t " +
            " where t.add_time > date_add(now(),interval - #{daysAgo} day) and t.deleted=0 " +
            " group by date_format(t.add_time,\"%Y-%m-%d\")")
    List<DayStatis> statisIncreaseUserCnt(@Param("daysAgo") int daysAgo);


    @Select(" select date_format(t.add_time,\"%Y-%m-%d\") as dayStr," +
            " count(1) as cnts,sum(actual_price) as amts  " +
            " from dts_order t " +
            " where t.add_time > date_add(now(),interval - #{daysAgo} day)" +
            " and t.deleted=0 and t.order_status not in(101,102,103) " +
            " group by date_format(t.add_time,\"%Y-%m-%d\")")
    List<DayStatis> statisIncreaseOrderCnt(@Param("daysAgo") int daysAgo);
}
